﻿using System;
using System.Collections.Generic;
using System.Linq;
using Locator.Products;
using DataAccess.BusinessEntities;
using System.ServiceModel.Activation;
using DataAccess;
using System.Threading;
using System.Web;
using System.ServiceModel;

namespace Locator.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(MaxItemsInObjectGraph=1000000)]
    public class ProductsService : IProductsService
    {
        public IProductsController ProductsController { get; set; }

        /// <summary>
        /// Initializes a new instance of the ProductsService class.
        /// </summary>
        public ProductsService()
        {
            this.ProductsController = new ProductsController(new SqlUnitOfWork());
            Thread.CurrentPrincipal = HttpContext.Current.User;
        }

        public List<Product> GetAllProducts()
        {
            return this.ProductsController.GetAllProducts();
        }

        public void DeleteProductForCurrentUser(int ID)
        {
            this.ProductsController.DeleteProductForCurrentUser(ID);
        }

        public void AddProductForCurrentUser(int productId)
        {
            this.ProductsController.AddProductForCurrentUser(productId);
        }

        public List<Substance> GetAllSubstances()
        {
            return this.ProductsController.GetAllSubstances();
        }

        public List<UserProduct> FindProductsContainingName(string name)
        {
            return this.ProductsController.FindProductsContainingName(name);
        }

        public List<UserProduct> GetProductsForCurrentUser()
        {
            return this.ProductsController.GetProductsForCurrentUser();
        }
    }
}
